package com.trkj.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.service.CheckWorkService;
import com.trkj.utils.DataGrid;
import com.trkj.vo.AttendanceTypeVo;
import com.trkj.vo.CheckWordDeptVo;
/**
 * 考勤管理controller层
 * @author 吴山峰
 *
 */
@Controller
public class CheckWorkController {
	@Autowired
	CheckWorkService checkWorkService;
	/**
	 * 前往考勤记录checkWork.jsp页面
	 * @return
	 */
	@RequestMapping("/to_CheckWork")
	public String toCheckWork() {
		return "checkWork";
	}
	/**
	 * 前往创建考勤记录createCheckWorkRecord.jsp页面
	 */
	@RequestMapping("/to_CreateCheckWorkRecord")
	public String toCreateCheckWorkRecord() {
		return "createCheckWorkRecord";
	}
	/**
	 * 查询所有部门和部门下的员工
	 */
	@RequestMapping("/find_CheckDeptAndEmp")
	@ResponseBody
	public List<CheckWordDeptVo> queryCheckDeptAndEmp() {
		return checkWorkService.queryCheckDeptAndEmp();
	}
	/**
	 * 根据员工编号查询员工的考勤记录
	 */
	@RequestMapping("/find_CheckWorkEmpInfoByEmpId")
	@ResponseBody
	public DataGrid queryCheckWorkEmpInfoByEmpId(Integer empId, Date starttime, Date endtime, Integer page, Integer rows,
												 @RequestParam(required = false, defaultValue = "attendanceId") String sort,
												 @RequestParam(required = false, defaultValue = "desc") String orde) {
		System.err.println(endtime+"--"+starttime+"--"+empId+"--");

		return checkWorkService.queryCheckWorkEmpInfoByEmpId(empId, starttime, endtime, page, rows, sort, orde);
	}
	/**
	 * 添加考勤记录
	 * @return 
	 * @return Time attendanceOffworktime,Time attendanceOnworktime,
	 * attendanceOffworktime+"--"+attendanceOnworktime+
	 */
	@RequestMapping("/add_CheckWorkRecord")
	@ResponseBody
	public boolean addCheckWorkRecord(String attendanceOffworktime,String attendanceOnworktime,Integer empId, Integer attypeid) {
		return checkWorkService.addCheckWorkRecord(attendanceOffworktime, attendanceOnworktime, empId, attypeid);
	}
	/**
	 * 查询所有考勤类型
	 */
	@RequestMapping("/find_AllAttType")
	@ResponseBody
	public List<AttendanceTypeVo> queryAllAttType() {
		return checkWorkService.queryAllAttType();
	}
	/**
	 * 根据员工id查询今天员工有没有考勤
	 */
	@RequestMapping("/find_EmpIsCheckWork")
	@ResponseBody
	public boolean queryEmpIsCheckWorkByEmpId(Integer empid) {
		return checkWorkService.queryEmpIsCheckWorkByEmpId(empid);
	}
}
